package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;

import butterknife.BindView;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.Qc_StoreListBean;
import retrofit2.http.POST;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：市场banner下五个图片
 */
public class ReclerViewAdapter extends RecyclerView.Adapter<ReclerViewAdapter.ViewHolder> {

    private Context context;
    private ArrayList<Qc_StoreListBean.DataBean> mList = new ArrayList<>();


    public ReclerViewAdapter(Context context, ArrayList<Qc_StoreListBean.DataBean> mList) {
        this.context = context;
        this.mList = mList;

    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_qcshop_class, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {

        RequestOptions options = new RequestOptions();
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);
        Glide.with(context).load(mList.get(position).getLogo()).apply(options).into(holder.logo);
        holder.shuoming.setText(mList.get(position).getName());
        holder.number.setText("¥"+mList.get(position).getGoods().get(0).getMarketprice()+"/"+mList.get(position).getGoods().get(0).getUnit()+"            "+
                "毛重："+mList.get(position).getGoods().get(0).getGoods_status()+mList.get(position).getGoods().get(0).getUnit());
        holder.jiajiage.setText("¥"+mList.get(position).getGoods().get(0).getDiscountprice()+"/"+mList.get(position).getGoods().get(0).getUnit());
        holder.number.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView tuoyuan;
        private final ImageView logo;
        private final TextView shuoming;
        private final TextView number;
        private final TextView jiajiage;
        private final TextView jian;
        private final TextView num;
        private final TextView add;

        public ViewHolder(View view) {
            super(view);
            tuoyuan = view.findViewById(R.id.iv_tuoyuan);
            logo = view.findViewById(R.id.iv_shop_logo);
            shuoming = view.findViewById(R.id.tv_shuoming);
            number = view.findViewById(R.id.tv_number);
            jiajiage = view.findViewById(R.id.jiage_jia);
            jian = view.findViewById(R.id.tvJian);
            num = view.findViewById(R.id.tv_num);
            add = view.findViewById(R.id.tv_add);
        }
    }

}
